//
//  HODepartmentEntity.m
//  微度报修
//
//  Created by foguo-mac-1 on 6/17/16.
//  Copyright © 2016 WeiDu. All rights reserved.
//

#import "HODepartmentEntity.h"
#import "HOConstants.h"
#import "HOUtils.h"

@implementation HODepartmentEntity
@synthesize departmentId;
@synthesize departmentName;

- (instancetype)init
{
    if(self = [super init])
    {
        self.firstLetter = @"";
    }
    return self;
}

- (void)parseDic:(NSDictionary *)dic
{
	self.departmentId = [[dic objectForKey:kHO_FIELD_DepartmentId] intValue];
	self.departmentName = [dic objectForKey:kHO_FIELD_DepartmentName];
//	[self firstCharactor];
    self.pinyin = [HOUtils getValideString:[dic objectForKey:kHO_FIELD_GetContact_Pinyin]];
    if(self.pinyin.length > 0)
    {
        self.firstLetter = [self.pinyin substringToIndex:1];
    }
}

//获取拼音首字母(传入汉字字符串, 返回大写拼音首字母)
- (void)firstCharactor
{
	if(self.departmentName.length == 0)
	{
		self.firstLetter = @"#";
		self.pinyin = @"";
		return;
	}
//	NSLog(@"firstCharactor userName：%@", self.departmentName);
	//转成了可变字符串
	NSMutableString *str = [NSMutableString stringWithString:self.departmentName];
	//先转换为带声调的拼音
	CFStringTransform((CFMutableStringRef)str,NULL, kCFStringTransformMandarinLatin,NO);
	//再转换为不带声调的拼音
	CFStringTransform((CFMutableStringRef)str,NULL, kCFStringTransformStripDiacritics,NO);
	//转化为大写拼音
	NSString *pinYin = [str capitalizedString];
	//获取并返回首字母
	self.firstLetter = [[pinYin substringToIndex:1] uppercaseString];
	self.pinyin = pinYin;
	//	return [pinYin substringToIndex:1];
}

- (void)dealloc
{
	self.departmentName = nil;
	[super dealloc];
}
@end
